package cn.wolfcode.shop.service.impl;

import cn.wolfcode.shop.domain.SeckillOrder;
import cn.wolfcode.shop.mapper.SeckillOrderMapper;
import cn.wolfcode.shop.redis.RedisService;
import cn.wolfcode.shop.redis.SeckillOrderPrefixKey;
import cn.wolfcode.shop.service.ISeckillOrderService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by wolfcode-lanxw
 */
@Service
public class SeckillOrderServiceImpl implements ISeckillOrderService {
    @Autowired
    private SeckillOrderMapper seckillOrderMapper;
    @Autowired
    private RedisService redisService;
    @Override
    public SeckillOrder getUserSeckillOrder(Long userId, Long goodId) {
        return seckillOrderMapper.getUserSeckillOrder(userId,goodId);
    }
    @Transactional
    @Override
    public void createSeckillOrder(Long userId, Long goodId, String orderNo) {
        SeckillOrder seckillOrder = new SeckillOrder();
        seckillOrder.setUserId(userId);
        seckillOrder.setGoodId(goodId);
        seckillOrder.setOrderNo(orderNo);
        seckillOrderMapper.insert(seckillOrder);
        redisService.set(SeckillOrderPrefixKey.SECKILL_ORDER,userId+":"+goodId,seckillOrder);
    }
}
